import warnings
warnings.filterwarnings("ignore")
from scipy.stats import gaussian_kde
import scipy.optimize as sop
from scipy import linspace, array, log, arange
import sys

def search_limits(serie, perc):
	fk = gaussian_kde(serie)
	xk = linspace(min(serie),max(serie),len(serie))
	yk = fk.evaluate(xk)
	vls = array(serie)
	
	def funcion(x,p):
		return fk.integrate_box_1d(min(serie),x) - p
	
	x0 = sop.fsolve(funcion,vls.mean()-vls.std(),args=(perc))
	x1 = sop.fsolve(funcion,vls.mean()+vls.std(),args=(1-perc))
	
	return (x0,x1)
	

